package tt.dz.egobus.servicemanager.cycle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.annotation.WebListener;

/**
 * @author Anson
 * @date 17-4-5
 * @name 初始化默认值的时候
 * @since 1.0.4
 */
@WebListener
public class WebServletContextCycle implements ServletContextCycle {


    private final AppCycleProcessor processor;

    private static final Logger LOGGER =
            LoggerFactory.getLogger(WebServletContextCycle.class);

    public WebServletContextCycle() {
        this.processor = new DefaultAppCycleProcessor();
    }


    @Override
    public void shutdownHook() {
        LOGGER.info("应用关闭挂钩执行");
        //  Runtime.getRuntime().addShutdownHook(shutdownHookOne);
    }

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        if (this.processor.isProcessor()) {
            this.processor.processorInit();
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        if (this.processor.isProcessor()) {
            this.processor.processorDestroyed();
        }
    }
}
